package cn.geminis.lowcode.compiler.code;

import cn.geminis.lowcode.compiler.util.JdkTreeMakerUtils;
import com.sun.source.tree.LambdaExpressionTree;

import java.util.List;

/**
 * @author puddi
 */
public class LcLambda extends AbstractExpression<LambdaExpressionTree> {

    private final List<LcVariable> params;

    private final List<AbstractStatement<?>> body;

    public LcLambda(List<LcVariable> params, AbstractStatement<?>... body) {
        this.params = params;
        this.body = List.of(body);
    }

    @Override
    protected LambdaExpressionTree createJdkTree() {
        return JdkTreeMakerUtils.lambda(
                this.params.stream().map(LcVariable::getJdkTree).toList(),
                new LcBlock(this.body).getJdkTree()
        );
    }
}
